<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队名称">
              <select-team-input v-model="queryParam.teamId" :teamType="0" :tdlx="3" multi/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队负责人">
              <select-user-by-dep
                  v-model="queryParam.mainLeader" :multi="false"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="时间">
              <a-date-picker
                mode="year"
                placeholder="请选择年度"
                format="YYYY"
                v-model="queryParam.period"
                style="width:100%"
                :allowClear="false"
                :open="yearShowOne"
                @openChange="openChangeOne"
                @panelChange="panelChangeOne"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('资金池明细表')" :disabled="isDisabledAuth('ErpCapitalAllotReportList:export')">导出</a-button> 
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :components="drag(columns)"
        bordered
        rowKey="teamId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{getCheckboxProps:getCheckboxProps,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="expensesPay" slot-scope="text, record">
          <a @click="getPaymentAmount(record)">{{ text }}</a>
        </template>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
      <ErpFinanceCapitalReportPenetrate ref="capitalReport"></ErpFinanceCapitalReportPenetrate>
    </div>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import moment from 'moment'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import ErpFinanceCapitalReportPenetrate from '@/views/scy/penetrate/ErpFinanceCapitalReportPenetrate'
  import {tableDragResize} from '@/utils/draggable-multistage'

  export default {
    name: 'ErpCapitalAllotReportList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin,tableDragResize],
    components: {
      SelectTeamInput,
      SelectUserByDep,
      ErpFinanceCapitalReportPenetrate
    },
    data () {
      return {
        queryParam:{
          period:moment(new Date()).format('YYYY'),
          mainLeader:"",
          teamId:""
        },
        //年度计划的打开关闭状态，true为打开，false为关闭
        yearShowOne:false,
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        description: '资金调拨明细',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (text,r,index) {
              return (!text.rowIndex) ? (parseInt(index) + 1) : text.rowIndex;
            }
          },
          {
            title:'团队主负责人',
            align:"center",
            dataIndex: 'mainLeader_dictText',
            width:150,
            ellipsis: true,
          },
          {
            title:'团队名称',
            align:"center",
            dataIndex: 'teamId_dictText',
            ellipsis: true,
            width:150,
          },
          {
            title:'期初结余（元）',
            align:"center",
            dataIndex: 'openingBalance',
            width:150,
            ellipsis: true,
          },
          {
            title:'本期开票（元）',
            align:"center",
            dataIndex: 'currentInvoice',
            width:150,
            ellipsis: true,
          },
          {
            title:'本期回款（元）',
            align:"center",
            dataIndex: 'currentCollectMoney',
            width:150,
            ellipsis: true,
          },
          {
            title:'切割收入/费用（元）',
            align:"center",
            dataIndex: 'cutCollectExpenses',
            width:150,
            ellipsis: true,
          },
          {
            title: '资金流出',
            dataIndex: 'data',
            children: [
              {
                title:'费用汇总',
                children: [
                  {
                    title:'费用支付（元）',
                    align:"center",
                    dataIndex: 'expensesPay',
                    scopedSlots: { customRender: 'expensesPay' },
                    ellipsis: true,
                    width:120,
                  },
                  {
                    title:'费用冻结（元）',
                    align:"center",
                    dataIndex: 'expensesFreeze',
                    ellipsis: true,
                    width:120,
                  },
                  {
                    title:'其中：前期投入（元）',
                    align:"center",
                    dataIndex: 'antecedentPay',
                    width:200,
                    ellipsis: true,
                  },
                  {
                    title:'职工薪酬（元）',
                    align:"center",
                    dataIndex: 'salaryPay',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'综管分摊（元）',
                    align:"center",
                    dataIndex: 'sharePay',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'其他补充（元）',
                    align:"center",
                    dataIndex: 'otherSupplement',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'费用汇总（元）',
                    align:"center",
                    dataIndex: 'expenseSum',
                    width:120,
                    ellipsis: true,
                  },
                ]
              },
              {
                title:'预付款',
                children:[
                  {
                    title:'期初冻结数（元）',
                    align:"center",
                    dataIndex: 'openingFrozenAmount',
                    width:200,
                    ellipsis: true,
                  },
                  {
                    title:'备用金（元）',
                    align:"center",
                    dataIndex: 'revolvingFund',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'预付款（元）',
                    align:"center",
                    dataIndex: 'advancePayment',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'本期冻结（元）',
                    align:"center",
                    dataIndex: 'currentFreeze',
                    width:120,
                    ellipsis: true,
                  },
                ]
              },
              {
                title:"预上缴利润",
                children:[
                  {
                    title:'比例（%）',
                    align:"center",
                    dataIndex: 'advanceProfitsRate',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'金额（元）',
                    align:"center",
                    dataIndex: 'advanceProfitsAmount',
                    width:120,
                    ellipsis: true,
                  },
                ]
              },
              {
                title:"预上缴管理费",
                children:[
                  {
                    title:'比例（%）',
                    align:"center",
                    dataIndex: 'advanceManageRate',
                    width:120,
                    ellipsis: true,
                  },
                  {
                    title:'金额（元）',
                    align:"center",
                    dataIndex: 'advanceManageAmount',
                    width:120,
                    ellipsis: true,
                  },
                ]
              },
              {
                title:'其他（元）',
                align:"center",
                dataIndex: 'otherAmount',
                width:120,
                ellipsis: true,
              },
              {
                title:'流出汇总（元）',
                align:"center",
                dataIndex: 'outflowSummary',
                width:120,
                ellipsis: true,
              },
            ],
          },
          {
            title:'期末结余（元）',
            align:"center",
            dataIndex: 'endingBalance',
            width:150,
            ellipsis: true,
          },
          {
            title:'应收账款（元）',
            align:"center",
            dataIndex: 'receivables',
            width:150,
            ellipsis: true,
          },
          {
            title:'保证金（元）',
            align:"center",
            dataIndex: 'bail',
            width:150,
            ellipsis: true,
          },
        ],
        url: {
          list: "/api/erp/finance/report/epCapitalPoolDetailReport/list", 
          exportXlsUrl: "/api/erp/finance/report/epCapitalPoolDetailReport/exportXls",
        },
        //代码生成后需手动设置流程编码
        dictOptions:{},
        superFieldList:[],
        newArr:[],
        newDataSource:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      searchQuery() {
        this.onClearSelected();
        this.loadData(1)
      },
      //打开付款弹窗
      getPaymentAmount(record){
        console.log(record);
        //先清空数据
        this.$refs.capitalReport.dataSource = []
        this.$refs.capitalReport.ipagination.total = 0
        //查询数据
        this.$refs.capitalReport.loading = true
        this.$refs.capitalReport.activeKey = '1'
        this.$refs.capitalReport.teamId = record.teamId
        this.$refs.capitalReport.period = this.queryParam.period
        this.$refs.capitalReport.searchReset()
         //打开弹窗
        this.$refs.capitalReport.visible = true
      },
      searchReset() {
        this.queryParam = {}
        this.$set(this.queryParam,"period",moment(new Date()).format('YYYY'));
        this.onClearSelected();
        this.loadData(1)
      },
      // 弹出日历和关闭日历的回调
      openChangeOne(status){
          //status是打开或关闭的状态
          this.yearShowOne =  !this.yearShowOne
      },
      // 得到年份选择器的值
      panelChangeOne(value){
        console.log(value);
        console.log(moment(value).format('YYYY'));
          this.queryParam.period = moment(value).format('YYYY')
          this.yearShowOne =  !this.yearShowOne
      },
      getQueryField() {
        // TODO 字段权限控制
        var str = 'id'
        this.columns.forEach(function (value) {
          // 多表头字段
          if (value.dataIndex == null && value.dataIndex === undefined) {
            value.children.forEach(function (item) {
              if(item.dataIndex == null && item.dataIndex === undefined){
                item.children.forEach(function (res){
                  str += ',' + res.dataIndex.replace('_dictText', '')
                })
              }else{
                str += ',' + item.dataIndex.replace('_dictText', '')
              }
            })
          } else {
            str += ',' + value.dataIndex
          }
        })
        return str
      },
      //流程审批结束禁用
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.rowIndex =='合计' 
          }
        }
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'date',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'handlerId',text:'经办人编号',dictCode:''})
        fieldList.push({type:'string',value:'handlerDeptId',text:'经办人部门ID',dictCode:''})
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'applicant',text:'申请公司',dictCode:''})
        fieldList.push({type:'string',value:'isRelContract',text:'是否关联合同',dictCode:'yes_no'})
        fieldList.push({type:'string',value:'payMode',text:'支付方式(字典)',dictCode:'payment_type'})
        fieldList.push({type:'string',value:'payeeName',text:'收款方名称',dictCode:''})
        fieldList.push({type:'string',value:'payeeBankName',text:'收款方开户行',dictCode:''})
        fieldList.push({type:'string',value:'payeeAccountNo',text:'收款方账户',dictCode:''})
        fieldList.push({type:'string',value:'payeeContacts',text:'收款联系人',dictCode:''})
        fieldList.push({type:'string',value:'payeeContactInfo',text:'收款联系方式',dictCode:''})
        fieldList.push({type:'string',value:'payRemark',text:'打款备注',dictCode:''})
        fieldList.push({type:'Text',value:'attachments',text:'附件',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
